package com.foxzzz.back.tracking;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution90 {
    public List<List<Integer>> subsetsWithDup(int[] nums) {
        Arrays.sort(nums);
        List<List<Integer>> reslut=new ArrayList<>();
        List<Integer> pre=new ArrayList<>();
        sub(reslut,pre,nums,0);
        return reslut;
    }

    public void sub(List<List<Integer>> result,List<Integer> list,int[] nums,int po){
        result.add(new ArrayList<>(list));
        for (int i = po; i < nums.length; i++) {
            if(i-1>=po&&nums[i-1]==nums[i])
                continue;
            list.add(nums[i]);
            sub(result,list,nums,i+1);
            list.remove(list.size()-1);
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution90().subsetsWithDup(new int[]{1,2,2}));
    }
}
